package com.jml.jdk8.方法引用;


import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import org.junit.Test;

/**
 * @author:jml
 * @date: 2019/11/27 0027 22:02
 * @description：
 */
public class StudentTest002实例and方法 {

    public static void main(String[] args) {
        Student zs = new Student("zs", 10);
        Student ls = new Student("ls", 40);
        Student ww = new Student("ww", 50);
        Student zl = new Student("zl", 90);
        List<Student> students = new ArrayList<>();
        students.add(zs);
        students.add(zl);
        students.add(ls);
        students.add(ww);
        StudentComparator studentComparator = new StudentComparator();
        students.sort((s1,s2)-> studentComparator.compareStudentByScore(s1,s2));
        students.sort(studentComparator::compareStudentByScore);
        students.forEach(student -> System.out.println(student.getScore()));
    }

    /**
     * 替代的只是一个函数接口,根据对象的方法的类型得到相应的函数接口的实例
     */
    @Test
    public void 方法引用001(){
        Function<Integer, Integer> function = new Function<Integer, Integer>() {
            @Override
            public Integer apply(Integer integer) {
                return null;
            }
        };
        StudentTest002实例and方法 studentTest002实例and方法 = new StudentTest002实例and方法();
        Function<Integer, Integer> function001 = studentTest002实例and方法::tt1;
        Integer apply = function001.apply(100);
        System.out.println(apply);
    }

    public Integer tt1(Integer integer){
        return integer*3;
    }

}
